home *** CD-ROM | disk | FTP | other *** search
- /**************************************
- ** EMAILNME.CPP - by John Adkins **
- ** 06/05/92 **
- ** **
- ** Email Name Class **
- **************************************/
-
- /**************************************
- ****** INCLUDES ********************
- **************************************/
-
- #include "emailnme.h"
-
- /**************************************
- ****** METHODS *********************
- **************************************/
-
- TEmailName::TEmailName(const char *str)
- {
- char *semi, *colon, *frst;
- char *temp;
-
- firstname=0;
- lastname=0;
- userid=0;
- servername=0;
- temp=strdup(str);
- colon=strrchr(temp,':');
- if(colon)
- {
- userid=strdup(colon+1);
- *colon=0;
- semi=strrchr(temp,';');
- if(semi)
- {
- servername=strdup(semi+1);
- *semi=0;
- frst=strchr(temp,' ');
- if(frst)
- {
- firstname=strdup(frst+1);
- *frst=0;
- }
- lastname=strdup(temp);
- }
- }
- free(temp);
- }
-
- TEmailName::TEmailName(TEmailName &source)
- {
- lastname=strdup(source.lastname);
- firstname=strdup(source.firstname);
- userid=strdup(source.userid);
- servername=strdup(source.servername);
- }
-
- TEmailName::~TEmailName()
- {
- if(firstname) free(firstname);
- if(lastname) free(lastname);
- if(userid) free(userid);
- if(servername) free(servername);
- }
-
- int TEmailName::isEqual(const Object &compare) const
- {
- int equal=0;
-
- if(compare.isA()==isA())
- {
- TEmailName &en=(TEmailName &)compare;
-
- if(stricmp(userid,en.userid)==0)
- equal=1;
- if(stricmp(lastname,en.lastname)==0)
- {
- for(int i=0, count=0; i<strlen(userid) && i<strlen(en.userid); i++)
- {
- if(userid[i]==en.userid[i])
- count++;
- }
- if(count>strlen(userid)/2 && count>strlen(en.userid)/2)
- equal=1;
- }
- }
- return(equal);
- }
-
- int TEmailName::isLessThan(const Object &compare) const
- {
- if(compare.isA()==isA())
- {
- TEmailName &en=(TEmailName &)compare;
-
- if(stricmp(lastname,en.lastname)<0)
- return(1);
- if(stricmp(lastname,en.lastname)==0)
- {
- if(stricmp(firstname,en.firstname)<0)
- return(1);
- if(stricmp(firstname,en.firstname)==0)
- {
- if(stricmp(servername,en.servername)<0)
- return(1);
- if(stricmp(servername,en.servername)==0)
- {
- if(stricmp(userid,en.userid)<0)
- return(1);
- else
- return(0);
- }
- }
- }
- }
- return(0);
- }
-
- void TEmailName::printOn(ostream &os) const
- {
- os << lastname << " " << firstname << ";" << servername << ":" << userid;
- }
-
- /**************************************
- ****** END OF EMAILNME.CPP *********
- **************************************/
-
-